package com.Iconcat.system.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {
    @ApiModelProperty(value = "是否成功")
    private  Boolean success;
    @ApiModelProperty(value = "返回数据")
    private Map<String,Object> data=new HashMap<>();
    @ApiModelProperty(value = "状态")
    private  Integer code;
    @ApiModelProperty(value = "返回消息")
    private  String message;
    @ApiModelProperty(value = "令牌")
    private  String token;

    public static Result ok(){
        Result result=new Result();
        result.setCode(ResultCode.SUCCESS.code());
        result.setSuccess(true);
        result.setMessage(ResultCode.SUCCESS.message());
        result.setToken(ResultCode.SUCCESS.token());
        return result;

    }
    public static Result error(){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR.code());
        result.setMessage(ResultCode.ERROR.message());
        return result;
    }
    public static Result userAlreadyExist() {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.USER_ACCOUNT_ALREADY_EXIST.code());
        result.setMessage(ResultCode.USER_ACCOUNT_ALREADY_EXIST.message());
        return result;
    }

    public static Result warn(){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.USER_ACCOUNT_important.code());
        result.setMessage(ResultCode.USER_ACCOUNT_important.message());
        return result;
    }
    public Result(Boolean success, Map<String, Object> data, Integer code, String message,String token) {
        this.success = success;
        this.data = data;
        this.code = code;
        this.message = message;
        this.token=token;
    }

    public Result() {
    }

    public Result success(Boolean success){
        this.success=success;
        return this;
    }
    public  Result code(Integer code){
        this.code=code;
        return this;
    }
    public  Result message(String message){
        this.message=message;
        return this;
    }
    public  Result data(String key,Object value){
        this.data.put(key,value);
        return  this;
    }
    public  Result data(Map<String,Object> map){
        this.setData(map);
        return  this;
    }
    public  Result token(String s, String token){
        this.token=token;
        return this;
    }
}
